package com.qf.cx.simplenms.common.utils;

import java.util.HashSet;
import java.util.Set;

public final class SetUtils {

	/**
	 * 求两个集合的交集.
	 * 
	 * @param a
	 * @param b
	 * @return a ∩ b
	 */
	public static <T> Set<T> getIntersection(final Set<T> a, final Set<T> b) {

		Set<T> set = new HashSet<>();

		a.stream().filter(t -> b.contains(t)).forEach(t -> set.add(t));

		return set;
	}

	/**
	 * 求两个集合的补集.
	 * 
	 * @param a
	 * @param b
	 * @return a - b
	 */
	public static <T> Set<T> getComplementary(final Set<T> a, final Set<T> b) {

		Set<T> set = new HashSet<>();

		a.stream().filter(t -> !b.contains(t)).forEach(t -> set.add(t));

		return set;
	}
	
	private SetUtils() {
	}
}
